{
LANG : PASCAL
PROB : numtri
}

program NUMTRI;
const
  fi = 'numtri.in';
  fo = 'numtri.out';
  max = 1001;
var
  d, a : array[0..max] of longint;
  r, maximum : longint;

function max2(x, y : longint) : longint;
begin
  if x > y then max2 := x
  else max2 := y;
end;

procedure process;
var
  i, j : integer;
begin
  fillchar(d, sizeof(d), 0);
  d[0] := 0;
  for i := 1 to r do
  begin
    fillchar(a, sizeof(a), 0);
    for j := 1 to i do read(a[j]);
    for j := i downto 1 do d[j] := max2(d[j-1], d[j])+a[j];
  end;
  maximum := 0;
  for i := 1 to r do
    if d[i] > maximum then maximum := d[i];
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  read(r);
  process;
  writeln(maximum);
  close(output);
  close(input);
end.